<?php
	#-------------------------------------------------------------#
	# This file is part of the Kumomado - Virtual Window Platform #
	# for PHP. (c) 2009 Tsai, Min Che <tirme0812@gmail.com>       #
	# Please visit http://www.kumomado.org/ for more information. #
	#                                                             #
	# This software is licensed under the GNU License v3. Please  #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#

	/**
	 * @package libraries/
	 * @author Tsai, Min Che
	 * @version 1.0
	 */
	class KumomadoLoader {
		public function load($class) {
			$class_name = substr($class, strrpos($class, '.') + 1);
			$path = substr(str_replace('.', DIRECTORY_SEPARATOR, strtolower($class)), 0, strrpos($class, '.') + 1).$class_name;
			$path = KUMOMADO_LIBRARIES_PATH.$path;
			$class_file = $path.'.class.php';
			$abstract_file = $path.'.abstract.php';
			$interface_file = $path.'.interface.php';
			if (file_exists($class_file) && is_readable($class_file)) {
				require_once $class_file;
			} else if (file_exists($abstract_file) && is_readable($abstract_file)) {
				require_once $abstract_file;
			} else if (file_exists($interface_file) && is_readable($interface_file)) {
				require_once $interface_file;
			} else {
				throw new KumomadoLibraryException('The class or interface '.$class.'['.$class_file.'] cloud not be loaded.');
			}
			if (!class_exists($class_name) && !interface_exists($class_name)) {
				throw new KumomadoLibraryException('The class or interface '.$class_name.' already included but the class or interface not exists!');
			}
		}
	}
?>